//
//  HotCViewCell.m
//  Travel_M_Travel
//
//  Created by Sun on 15/4/5.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "HotCViewCell.h"
#import "UIColor+AddColor.h"

@implementation HotCViewCell

- (void)dealloc
{
    [_imageView release];
    [_nameLabel release];
    [_firstDayLabel release];
    [_cycleLabel release];
    [_viewConunt release];
    [_local release];
    [_aboutHot release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        
        
        self.imageView = [[UIImageView alloc] init];
        // 加圆角
        _imageView.clipsToBounds = YES;
        _imageView.layer.cornerRadius = 5;
        [self addSubview:_imageView];
        [_imageView release];
        
        self.nameLabel = [[UILabel alloc] init];
        _nameLabel.textColor = [UIColor colorFromHexCode:@"#121a2a"];
        _nameLabel.font = [UIFont boldSystemFontOfSize:15];
        _nameLabel.adjustsFontSizeToFitWidth = YES;
        [_imageView addSubview:_nameLabel];
        [_nameLabel release];
        
        self.firstDayLabel = [[UILabel alloc] init];
        _firstDayLabel.textColor = [UIColor colorFromHexCode:@"#121a2a"];
        _firstDayLabel.font = [UIFont boldSystemFontOfSize:12];
        [_imageView addSubview:_firstDayLabel];
        [_firstDayLabel release];
        
        self.cycleLabel = [[UILabel alloc] init];
        _cycleLabel.font = [UIFont boldSystemFontOfSize:12];
        _cycleLabel.textColor = [UIColor colorFromHexCode:@"#121a2a"];
        [_imageView addSubview:_cycleLabel];
        [_cycleLabel release];
        
        self.viewConunt = [[UILabel alloc] init];
        _viewConunt.font = [UIFont boldSystemFontOfSize:12];
        _viewConunt.textColor = [UIColor colorFromHexCode:@"#121a2a"];
        [_imageView addSubview:_viewConunt];
        [_viewConunt release];
        
        self.local = [[UILabel alloc] init];
        _local.font = [UIFont boldSystemFontOfSize:12];
        _local.textColor = [UIColor colorFromHexCode:@"#121a2a"];
        [_imageView addSubview:_local];
        [_local release];
    }
    return self;
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    _imageView.frame = CGRectMake(0, 0, 290, 160);
    _nameLabel.frame = CGRectMake(10, 5, 270, 20);
    _firstDayLabel.frame = CGRectMake(10, 25, 100, 15);
    _cycleLabel.frame = CGRectMake(90, 25, 50, 15);
    _viewConunt.frame = CGRectMake(130, 25, 200, 15);
    _local.frame = CGRectMake(10, 40, 290, 15);
}

- (void)setAboutHot:(AboutHotData *)aboutHot
{
    if (_aboutHot != aboutHot) {
        [_aboutHot release];
        _aboutHot = [aboutHot retain];
    }
    
    NSString *str = self.aboutHot.cover_image_1600;
    str = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSURL *url = [NSURL URLWithString:str];
    [_imageView setImageWithURL:url];
    
    _nameLabel.text = self.aboutHot.name;
    _firstDayLabel.text = [self wayPointTime:_aboutHot.first_day];
    
    NSString *strDay = [[NSString stringWithFormat:@"%@", self.aboutHot.day_count] stringByAppendingString:@"天"];
    _cycleLabel.text = strDay;
    NSString *strView = [[NSString stringWithFormat:@"%@", self.aboutHot.view_count] stringByAppendingString:@"次浏览"];
    _viewConunt.text = strView;
    _local.text = self.aboutHot.popular_place_str;
}

- (NSString *)wayPointTime : (NSNumber *)numberTime
{
    NSTimeInterval timeTV = [numberTime doubleValue];
    
    //    NSString* timeStr = @"2011-01-26 17:40:50";
    NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"YYYY-MM-dd "]; // ----------设置你想要的格式,hh与HH的区别:分别表示12小时制,24小时制
    
    //设置时区,这个对于时间的处理有时很重要
    //例如你在国内发布信息,用户在国外的另一个时区,你想让用户看到正确的发布时间就得注意时区设置,时间的换算.
    //例如你发布的时间为2010-01-26 17:40:50,那么在英国爱尔兰那边用户看到的时间应该是多少呢?
    //他们与我们有7个小时的时差,所以他们那还没到这个时间呢...那就是把未来的事做了
    
    NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
    [formatter setTimeZone:timeZone];
    
    //    NSDate* date = [formatter dateFromString:timeStr]; //------------将字符串按formatter转成nsdate
    //    NSLog(@"data === %@",date);
    
    //    NSDate *datenow = [NSDate date];//现在时间,你可以输出来看下是什么格式
    //    NSLog(@"datanow === %@",datenow);
    //    NSString *nowtimeStr = [formatter stringFromDate:datenow];//----------将nsdate按formatter格式转成nsstring
    
    //    NSString *timeSp = [NSString stringWithFormat:@"%ld", (long)[datenow timeIntervalSince1970]];
    //    NSLog(@"timeSp(时间戳):%@",timeSp); //时间戳的值
    //    时间戳转时间的方法
    
    NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:timeTV];
    //    NSLog(@"(国际时区的时间)1415107016  = %@",confromTimesp);
    NSString *confromTimespStr = [formatter stringFromDate:confromTimesp];
    //    NSLog(@"(当前的时间)confromTimespStr =  %@",confromTimespStr);
    
    return confromTimespStr;
}



@end
